#include "StdAfx.h"
#include "SearchTitlePanelUI.h"

CSearchTitlePanelUI::CSearchTitlePanelUI(void): m_iIconIndex(-1)
{
	SetInset(CStdSize(0, 0));
}

CSearchTitlePanelUI::~CSearchTitlePanelUI(void)
{
}

LPCTSTR CSearchTitlePanelUI::GetClass() const
{
	return _T("SearchTitlePanelUI");
}

void CSearchTitlePanelUI::SetImage(int iIndex)
{
	m_iIconIndex = iIndex;
}

void CSearchTitlePanelUI::SetPos(RECT rc)
{
	RECT rcClient = { rc.left + 1, rc.top + 35, rc.right - 1, rc.bottom - 1 };
	CHorizontalLayoutUI::SetPos(rcClient);
	m_rcItem = rc;
}

void CSearchTitlePanelUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
	RECT rcFrame = { m_rcItem.left, m_rcItem.top + 34, m_rcItem.right, m_rcItem.bottom };
	CBlueRenderEngineUI::DoPaintFrame(hDC, m_pManager, rcFrame, UICOLOR_HEADER_SEPARATOR, UICOLOR_HEADER_SEPARATOR, UICOLOR_HEADER_BACKGROUND);
	RECT rcArc = { m_rcItem.left, m_rcItem.top + 14, m_rcItem.right, m_rcItem.top + 34 };
	RECT rcTemp = { 0 };
	if( ::IntersectRect(&rcTemp, &rcPaint, &rcArc) ) {
		CBlueRenderEngineUI::DoPaintArcCaption(hDC, m_pManager, rcArc, _T(""), 0);
	}
	if( m_iIconIndex >= 0 ) {
		HICON hIcon = m_pManager->GetThemeIcon(m_iIconIndex, 50);
		::DrawIconEx(hDC, m_rcItem.left + 5, m_rcItem.top, hIcon, 50, 50, 0, NULL, DI_NORMAL);
		::DestroyIcon(hIcon);
	}
	CHorizontalLayoutUI::DoPaint(hDC, rcPaint);
}

void CSearchTitlePanelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
	if( _tcscmp(pstrName, _T("image")) == 0 ) SetImage(_ttoi(pstrValue));
	else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue);
}

